using System;
using System.Collections.Generic;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Exceptions;

namespace SchEdu.Framework.Validators
{

    public class MachinePerWorkCenterValidator : Validator
    {
        int maxMachinePerWorkCenter = -1;

        public int MaxMachinePerWorkCenter
        {
            get { return maxMachinePerWorkCenter; }
            set { maxMachinePerWorkCenter = value; }
        }


        int minMachinePerWorkCenter = -1;

        public int MinMachinePerWorkCenter
        {
            get { return minMachinePerWorkCenter; }
            set { minMachinePerWorkCenter = value; }
        }


        public MachinePerWorkCenterValidator(SchEduData schEduData, int minMachinePerWorkCenter, int maxMachinePerWorkCenter)
            : base(schEduData)
        {
            this.minMachinePerWorkCenter = minMachinePerWorkCenter;
            this.maxMachinePerWorkCenter = maxMachinePerWorkCenter;
        }
        #region IValidator Members

        public override void Validate()
        {
            foreach (SchEduDataSet.WorkCenterRow workCenter in SchEduData.WorkCenter)
            {
                int count = workCenter.GetMachineRows().Length;
                if (minMachinePerWorkCenter != -1 && count < minMachinePerWorkCenter)
                {
                    throw new ValidatorException(string.Format(Resources.MinMachinePerWorkCenter, workCenter.Name, minMachinePerWorkCenter));
                }
                if (maxMachinePerWorkCenter != -1 && count > maxMachinePerWorkCenter)
                {
                    throw new ValidatorException(string.Format(Resources.MaxMachinePerWorkCenter, workCenter.Name, maxMachinePerWorkCenter));
                }
            }
        }

        #endregion
    }
}
